package wwy.Common;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import wwy.Common.orgEntity.LogicEntity;

import java.io.Serializable;
import java.util.List;

@CrossOrigin
public abstract class LogicController<S extends LogicService<D,T,ID>, D extends LogicDao<T,ID>,T extends LogicEntity, ID extends Serializable>{

    protected S service;

    public LogicController(S ls){
        this.service = ls;
    }
        @GetMapping("/get")
        @Operation(summary = "通过ID获取实体")
        @Hidden
        public T GET(@RequestParam ID id){
            return service.GET(id);
        }

        @Operation(summary = "获取所有实体")
        @GetMapping("/getAll")
        @Hidden
        public List<T> getAll(){
            return service.getAll();
        }

        @Operation(summary = "修改实体")
        @PostMapping("/put")
        @Hidden
        public T PUT(@RequestBody T entity, T newEntity){
            return service.PUT(entity, newEntity);
        }

        @Operation(summary = "添加实体")
        @PostMapping("/post")
        @Hidden
        public T POST(@RequestBody T  entity){
            return service.POST(entity);
        }

        @Operation(summary = "通过ID删除实体")
        @GetMapping("/delete")
        @Hidden
        public void DELETE(@RequestParam ID id){
            service.DELETE(id);
        }
}